﻿/************************************************************************
** 文  件：
**	DateUtil.h
** 功  能：
**	系统时间日期转换操作
** 作  者：
**	email:lixx2048@163.com
**  wechat:lixiang6153
**  QQ:941415509
** 日  期：
**	2024/03/15	14:00:00
** 说  明：
**	无
** 版  本：
**	2024/03/15	14:00:00		1.0		lixx2048@163.com
/************************************************************************/
#pragma once
#include <ctime>
#include <iostream>
#include <string>
#ifdef _WIN32
#include <windows.h>
#endif
#include <boost/chrono.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>    
#include <boost/date_time/posix_time/posix_time.hpp> 
#include <boost/format.hpp>

// 时间点定义
typedef boost::chrono::system_clock::time_point TIME_POINT;

class DateTime
{
public:
	DateTime();
	DateTime(int y, int m, int d, int h, int M, int s);
	virtual ~DateTime();

public:
	static DateTime Now();
	// 获取当前时间字符串
	static std::string CurrentTime();
	// "%Y-%m-%d %H:%M:%S.%f"
	static DateTime FromString(std::string time);
	// ISO:20201211
	static std::string GetLocalDay();
	// ISO:2020-10-10T10:12:55.003
	static std::string GetLocalIOSTime();
	// SIMPLE:2020-10-10 11:10:56
	static std::string GetCurrentTime();
	static DateTime Get(std::string time);
	static DateTime GetFromHHMMSS(std::string time);
	static std::string Transformat(std::string source, std::string sourcefmt, std::string destfmt);
	// 2020-10-10T10:12:55.003 => time_t
	static std::time_t IOSTimeToTM(std::string time, std::string fmt);
	// seconds between time
	static std::time_t Diff(DateTime begin, DateTime end);
	// 获取当前时间点
	static boost::chrono::system_clock::time_point CurrrentTimePoint();
	// 时间点时长-秒
	static double Duration(boost::chrono::system_clock::time_point& start);
	// 当前时间在区间内
	static bool BetweenTimeNow(std::string start, std::string stop);

public:
	void From(std::string time);
	// "%Y-%m-%d %H:%M:%S.%f"
	void From(std::string time, std::string fmt);
	// 10:10:10
	void FromNormalHHMMSS(std::string time);
	void From(std::tm time);
	void LocalTime();
	void From(time_t t);
#ifdef _WIN32
	void From(FILETIME ft);
#endif
	bool Equal(DateTime& time);
	bool EqualDay(DateTime& time);
	bool EqualTime(DateTime& time);
	int  Compare(DateTime& DateUtil);

	void UpdateDate(DateTime& date);
	void UpDateUtil(DateTime& time);
	void UpdateDate(int y, int m, int d);
	void UpDateUtil(int h, int m, int s);
	// 正值为增加,负数为减
	DateTime& AddSeconds(int seconds);
	// 2020-10-01 10:10:10
	std::string ToNormalString();
	// 10:10:10
	std::string ToNormalHHMMSS();
	// 1900-Jan-01 00:00:00
	std::string ToSimpleString();
	// 20201010T233210
	std::string ToIOSString();
	// YYYY-MM-DDTHH:MM:SS
	std::string ToIOSExtString();
	boost::posix_time::ptime ToPTime();
	std::time_t Totm();
	// 时间是否无效[初始值]
	bool Invalid();

public:
	int  GetDayOfWeek();
	int  GetYear();
	int  GetMonth();
	int  GetDay();
	int  GetHour();
	int  GetMinute();
	int  GetSecond();
	int  GetMicSecond();

protected:
	void Update(boost::posix_time::ptime ptime);

public:
	int m_year;
	int m_month;
	int m_day;
	int m_hour;
	int m_minute;
	int m_second;
	uint64_t m_mic_second;
};